TMP_DIR=../data
function mk_field_data_file
{
	FMT_NAME=$1
	echo "1. select format fields"
	01_s_msg_fields.pl $FMT_NAME > $TMP_DIR/$FMT_NAME.fmt
}

function mig_S_A2A003
{
	echo # $1
	APP_NAME=$1
	M_LST=`00_s_rule_list_a2a003.pl $1`

# Requirement, 20091117 : not exists layout relevance rule : only deferred_tran_transform
#	M_LST=[22],IBM-APOB2C10-RDBS002,IBM-APOB2C10-RDBS002,S_A2A003,R_APOB2C10-RDBS002_NULL

# Requirement.20091117
#	M_LST=[24],IBM-APOB2C11-RDBS001,CCD-TCMFAPR1-RDBS001,S_A2A003,R_APOB2C11-RDBS001_N3
# Error.20091125
#	M_LST=[99],IBM-APOB2CB4-RDBS001,CCD-TCMFCRD1-RDBS001,S_A2A003,R_APOB2CB4-RDBS001_N1
#	M_LST=[1],IBM-APOA1C01-RDBS001,CCD-TCMFMEM1-RDBS001,S_A2A003,R_APOA1C01-RDBS001_N1
#	M_LST=[1],IBM-APOA1C01-RDBS001,CCD-TCMFMEM1-RDBS001,S_A2A003,R_APOA1C01-RDBS001_N1
#	M_LST=[346],IBM-POB2S1K1-RDBS001,CCD-TCMFAPR1-RDBS001,S_A2A003,R_POB2S1K1-RDBS001_N1
#	M_LST=[347],IBM-POB2S1K1-RDBS001,IBM-POB2S1K1-RDBS001,S_A2A003,R_POB2S1K1-RDBS001_N2
#	M_LST=[346],IBM-POB2S1K1-RDBS001,CCD-TCMFAPR1-RDBS001,S_A2A003,R_POB2S1K1-RDBS001_N1

	echo > $TMP_DIR/$1.lst
	for M_ITM in $M_LST
	do
		echo 
		echo "* LST:$M_ITM"

		echo $M_ITM >> $TMP_DIR/$1.lst

		SOURCE_IFID=`echo $M_ITM | cut -d ',' -f 2`
		TARGET_IFID=`echo $M_ITM | cut -d ',' -f 3`
		APP_NAME=`echo $M_ITM | cut -d ',' -f 4`
		RULE_NAME=`echo $M_ITM | cut -d ',' -f 5`

		R_LINE=`03_s_layout_for_rule.pl $APP_NAME $RULE_NAME`
		LAYOUT_NAME3=`echo $R_LINE|cut -d ',' -f 6`
		LAYOUT_NAME4=`echo $R_LINE|cut -d ',' -f 7`

#		echo "======R_LINE:$R_LINE"
#		echo "======LAYOUT_NAME3:$LAYOUT_NAME3"
#		echo "======LAYOUT_NAME4:$LAYOUT_NAME4"

		if [ -n "$LAYOUT_NAME3" ]
		then
			mk_field_data_file $LAYOUT_NAME3
			02_i_layout.pl $LAYOUT_NAME3
		fi

		if [ -n "$LAYOUT_NAME4" ]
		then
			mk_field_data_file $LAYOUT_NAME4
			02_i_layout.pl $LAYOUT_NAME4
			04_i_transform_rule.pl $APP_NAME $RULE_NAME $LAYOUT_NAME4 $LAYOUT_NAME3
		else
			RULE_NAME=""
		fi


		08_i_deferred_transform_rule.pl $SOURCE_IFID $TARGET_IFID $RULE_NAME $LAYOUT_NAME4



#exit
	done
}

function mig_S_A2A001
{
	echo "# $1"
	APP_NAME=$1
#	M_LST=`00_s_rule_list.pl $1`
#	M_LST=`cat yy`


# Requirement.20091120
#	M_LST=[154],STR0001,N3M1,N,todo,R_N3M1_I02,,S_A2A002
# not have layout
#	M_LST=[4],STR0015,001000,N,todo,R_001000_IE1,,S_A2A004
#	M_LST=[219],STR0001,B4MN,Y,todo,R_B4MN_IM1,,S_A2E001
#	M_LST=[633],STR0001,S1M7,Y,todo,R_S1M8_I02,,S_A2E001
#	M_LST=[730],STR0015,000800,Y,todo,R_0008XX_IE1,,S_A2E001
#	M_LST=[731],STR0015,000800,Y,todo,R_KCBRUN_0008XX_IE1,,S_A2E001
#	M_LST=[733],STR0015,000801,N,todo,R_0008XX_IE1,,S_A2E001
#	M_LST=[734],STR0015,000801,N,todo,R_KCBRUN_0008XX_IE1,,S_A2E001
#	M_LST=[736],STR0015,000810,Y,todo,R_0008XX_IE1,,S_A2E001
#	M_LST=[737],STR0015,000810,Y,todo,R_KCBRUN_0008XX_IE1,,S_A2E001
#	M_LST=[739],STR0015,000820,N,todo,R_0008XX_IE1,,S_A2E001
#	M_LST=[740],STR0015,000820,N,todo,R_KCBRUN_0008XX_IE1,,S_A2E001
#	M_LST=[742],STR0015,000830,N,todo,R_0008XX_IE1,,S_A2E001
#	M_LST=[749],STR0015,002000,Y,todo,R_002000_IE1,,S_A2E001
#	M_LST=[750],STR0015,003000,N,todo,R_003000_IE1,,S_A2E001
#	M_LST=[753],STR0015,005010,Y,todo,R_005010_IE1,,S_A2E001
#	M_LST=[6],STR0015,000800,Y,todo,R_0008XX_IE1,,S_A2E002
#	M_LST=[7],STR0015,000801,N,todo,R_0008XX_IE1,,S_A2E002
#	M_LST=[12],STR0015,001000,N,todo,R_001000_IE1,,S_A2E002
#	M_LST=[20],STR0015,029100,N,,R_029100_IE2,CF_029100_IE2,S_A2E002
#	M_LST=[21],STR0015,030110,N,,R_030110_IE2,CF_030110_IE2,S_A2E002
#	M_LST=[23],STR0015,034100,N,,R_034100_IE2,CF_034100_IE2,S_A2E002
#	M_LST=[24],STR0015,041110,N,,R_041110_IE2,CF_041110_IE2,S_A2E002
#	M_LST=[25],STR0015,053110,N,,R_053110_IE2,CF_053110_IE2,S_A2E002
#	M_LST=[26],STR0015,055110,N,,R_055110_IE2,CF_055110_IE2,S_A2E002
#	M_LST=[14],STR0015,002000,Y,todo,R_002000_IE1,,S_A2E002
#	M_LST=[732],STR0001,Z501,N,todo,R_Z501_IM3,,S_E2A001
#	M_LST=[734],STR0015,000800,N,todo,R_0008XX_IE2,,S_E2A001
#	M_LST=[735],STR0015,000800,N,todo,R_KCBRUN_0008XX_IE2,,S_E2A001
#	M_LST=[1],STR0001,P3A1,N,todo,R_P3A1_IE1,,S_E2A002
#	M_LST=[6],STR0015,000800,N,todo,R_0008XX_IE1,,S_E2A002
#	M_LST=[9],STR0015,000820,Y,todo,R_0008XX_IE1,,S_E2A002
#	M_LST=[19],STR0015,029100,Y,,R_029100_IE1,CF_029100_IE1,S_E2A002
#	M_LST=[20],STR0015,030110,Y,,R_030110_IE1,CF_030110_IE1,S_E2A002
#	M_LST=[88],STR0015,112008,N,todo,R_112008_IK2,,S_E2A002
#	M_LST=[71],STR0001,A502,Y,todo,R_A502_IE1,,S_A2A001
#	M_LST=[101],STR0001,CS04,Y,,,,S_A2A001
#	M_LST=[184],STR0001,A101,N,todo,R_A101_I01,,S_A2A001
#	M_LST=[68],STR0001,A502,N,,,,S_A2A002
#	M_LST=[69],STR0001,A502,N,todo,R_A502_IE2,,S_A2A002
#	M_LST=[99],STR0001,CS04,N,,,,S_A2A002


#	M_LST=[138],STR0001,E801,N,,,,S_A2A002
#	M_LST=[139],STR0001,E801,N,todo,R_E801_IE2,,S_A2A002
#	M_LST=[35],STR0001,A1J1,Y,,,,S_A2A001
#	M_LST=[36],STR0001,A1J1,Y,todo,R_A1J1_IM3,,S_A2A001
#	M_LST=[37],STR0001,A1J1,Y,todo,R_A1J1_IM1,,S_A2A001
#	M_LST=[622],STR0001,S1K1,N,todo,R_S1K1_I32,,S_E2A001
#	M_LST=[732],STR0015,000801,Y,,R_KCBRUN_0008XX_IE2,CF_KCBRUN_IE1,S_E2A001
#	M_LST=[37],STR0001,A1J1,Y,todo,R_A1J1_IM1,,S_A2A001
#	M_LST=[131],STR0015,302066,N,,R_302066_IE2,FF_302066_IE1,S_E2A002
#	M_LST=[132],STR0015,302066,N,todo,R_302066_IK2,,S_E2A002
#	M_LST=[129],STR0015,302067,Y,,R_302067_IE1,FF_302067_IE1,S_A2E002
#	M_LST=[133],STR0015,302067,N,,R_302067_IE2,CF_302067_IE2,S_E2A002
#	M_LST=[134],STR0015,302067,N,todo,R_302067_IK2,,S_E2A002
# 2009.12.15
#	M_LST=[20],STR0015,055110,N,,R_055110_IE2,CF_055110_IE2,S_A2E002
#	M_LST=[24],STR0015,065110,Y,,R_065110_IE1,CF_065110_IE1,S_E2A002
#	M_LST=[138],STR0001,B2K2,Y,todo,R_B2K2_IM1,,S_A2E001
#	M_LST=[16],STR0015,034100,Y,,R_034100_IE1,CF_034100_IE1,S_E2A002
# 2009.12.24
#	M_LST=[33],STR0015,100000,Y,,,FF_100000_IE1,S_A2E002
#	M_LST=[82],STR0015,200000,Y,,,FF_200000_IE1,S_A2E002
# 2009.12.30
#	M_LST=[350],STR0001,G16S,N,,,CF_G10S_I02,S_E2A001
#	M_LST=[1],IBM-APOA1C01-RDBS001,CCD-TCMFMEM1-RDBS001,S_A2A003,R_APOA1C01-RDBS001_N1
# 2010.10.05
#	M_LST=[166],STR0001,B2M4,N,,,CF_B2M4_I02,S_E2A001
#	M_LST=[151],STR0001,N3M1,N,,,CF_N3M1_I02,S_A2A002
#	M_LST=[352],STR0001,G16S,Y,,,CF_G10S_I01,S_A2E001
#	M_LST=[360],STR0001,G1AS,Y,,,CF_G10S_I01,S_A2E001
#	M_LST=[371],STR0001,G1JS,Y,,,CF_G10S_I01,S_A2E001
#	M_LST=[337],STR0001,G10S,N,,,CF_G10S_I02,S_E2A001
#	M_LST=[5],STR0015,000800,Y,,R_0008XX_IE2,CF_0008XX_IE2,S_A2E002
#	M_LST=[5],STR0015,000800,N,,R_0008XX_IE1,CF_0008XX_IE1,S_E2A002
#	M_LST=[468],STR0001,N1JE,Y,,,FF_N1JE_I01,S_A2E001
#	M_LST=[469],STR0001,N1JE,N,,,FF_N1JE_I02,S_E2A001
#	M_LST=[32],STR0015,103141,N,,R_103141_IE1,CF_103141_IE2,S_A2E002
#	M_LST=[4],STR0001,B2KE,Y,todo,R_B2KE_IT1,,S_A2E001
#	M_LST=[3],STR0001,B2KE,N,todo,R_B2KE_IT2,,S_E2A001
	M_LST=[32],STR0015,103141,N,,R_103141_IE1,CF_103141_IE2,S_A2E002

	for M_ITM in $M_LST
	do
		echo 
		echo "* LST:$M_ITM"

		FLD_NAME1=`echo $M_ITM | cut -d ',' -f 2`
		ARG_VAL=`echo $M_ITM | cut -d ',' -f 3`
		REQ=`echo $M_ITM | cut -d ',' -f 4`
		EXP=`echo $M_ITM | cut -d ',' -f 5`
		RULE=`echo $M_ITM | cut -d ',' -f 6`
		LAYOUT=`echo $M_ITM | cut -d ',' -f 7`

#echo =REQ=$REQ==
#echo =RULE=$RULE==
#echo =LAYOUT=$LAYOUT==
		echo -- FLD_NAME:[$FLD_NAME1], RULE:[$RULE], LAYOUT:[$LAYOUT]

		if [ -n "$RULE" ]
		then
			echo "====<$APP_NAME=$RULE=>="
			R_LINE=`03_s_layout_for_rule.pl $APP_NAME $RULE`
			#echo "===R_LINE=<=$R_LINE=>="
			LAYOUT_SRC=`echo $R_LINE|cut -d ',' -f 6`
			echo "======LAYOUT_SRC:$LAYOUT_SRC"

			LAYOUT_TGT=`echo $R_LINE|cut -d ',' -f 7`
			echo "======LAYOUT_TGT:$LAYOUT_TGT"

			if [ -n "$LAYOUT_SRC" ]
			then
				mk_field_data_file $LAYOUT_SRC
			fi

			if [ -n "$LAYOUT_TGT" ]
			then
				mk_field_data_file $LAYOUT_TGT
			fi

			if [ -n "$LAYOUT_SRC" ]
			then
				02_i_layout.pl $LAYOUT_SRC $LAYOUT_TGT 'rev'
			fi

			if [ -n "$LAYOUT_TGT" ]
			then
				02_i_layout.pl $LAYOUT_TGT $LAYOUT_SRC 'not_rev'

				04_i_transform_rule.pl $APP_NAME $RULE $LAYOUT_TGT $LAYOUT_SRC

			fi

			06_i_online_tran.pl $FLD_NAME1 $ARG_VAL $REQ $APP_NAME $RULE $LAYOUT_SRC $EXP

		elif [ -n "$LAYOUT" ]
		then
			mk_field_data_file $LAYOUT
			02_i_layout.pl $LAYOUT

			06_i_online_tran.pl $FLD_NAME1 $ARG_VAL $REQ $APP_NAME 0$RULE $LAYOUT $EXP
		else
			06_i_online_tran.pl $FLD_NAME1 $ARG_VAL $REQ $APP_NAME 0$RULE $LAYOUT $EXP

		fi
#exit
	done
}

function app_mig
{
	APP_NAME=$1

	if [ $1 == 'S_A2A003' ]
	then
		mig_S_A2A003 $APP_NAME
	else
		mig_S_A2A001 $APP_NAME
	fi
}
function mig_per_rule
{
	APP_NAME=$1
	RULE_NAME=$2

	M_ITM=`00_s_msglist_per_rule.pl $APP_NAME $RULE_NAME`

	LAYOUT1=`echo $M_ITM | cut -d ',' -f 6`
	LAYOUT2=`echo $M_ITM | cut -d ',' -f 7`
echo $LAYOUT1
echo $LAYOUT2
	mk_field_data_file $LAYOUT1
	02_i_layout.pl $LAYOUT1

	mk_field_data_file $LAYOUT2
	02_i_layout.pl $LAYOUT2
	04_i_transform_rule.pl $APP_NAME $RULE_NAME $LAYOUT2 $LAYOUT1
}

# rule mig. test : RULE
#app_mig S_E2A002

# layout mig. test : LAYOUT
#app_mig S_E2A001

## rule mig. test : null, null
#app_mig S_A2A001

#export SRC_DB=KEBCS_130
export SRC_DB=KEBCS_140
#export TGT_DB=KEBCS_160
export TGT_DB=KEBCS_DHUB1

#---------------------------------------
#app_mig S_A2A003
#app_mig S_A2A001
#app_mig S_A2A002

#app_mig S_A2A004
#app_mig S_A2A005

#app_mig S_A2E001
app_mig S_A2E002

#app_mig S_E2A001
#app_mig S_E2A002
#
#app_mig S_A2A007

#- abnormal case --------------------------------------
#mig_per_rule S_A2A001 R_FLAG_HDDR_I01

#- only form ------------------------------------------
#mk_field_data_file FF_USER_I01
#02_i_layout.pl FF_USER_I01

######mk_field_data_file CF_IBM-OVER_I02
#02_i_layout.pl CF_IBM-OVER_I02
